/* All these methods are legacy, but are kept for documentation and reference */
function NSResolver(prefix) {
  if(prefix == 'x') {
    return 'http://www.w3.org/2002/xforms';
  }
  else if(prefix == 'ev') {
    return 'http://www.w3.org/2001/xml-events'
  }
  else if(prefix == 'xhtml') {
    return 'http://www.w3.org/1999/xhtml'
  }
  else if(prefix == 'xsd') {
    return 'http://www.w3.org/2001/XMLSchema'
  }
  else if(prefix == 'pn') {
    return 'http://pnengine.org/scheme'
  }
  else  {
  //this shouldn't ever happen
    return null;
  }
}
		
function copyToOutput(place, source, target){
  model = document.getElementById("model1")
  instance = model.getInstanceDocument("token-instance");
  val = document.evaluate("//place[@id='"+place+"']//token[@href=../@chosen_token]//"+source, instance, NSResolver, XPathResult.STRING_TYPE,null).stringValue;
  document.evaluate("//output//"+target, instance, NSResolver, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue.textContent = val;
  model.rebuild();
  model.recalculate();
  model.refresh();
}

function searchForCopyToOutput(){
  copyTags = document.evaluate("//pn:copy", document, NSResolver, XPathResult.ANY_TYPE,null);
  copyTag = copyTags.iterateNext();
  while(copyTag){
    copyToOutput(copyTag.getAttribute('place'), copyTag.getAttribute('source'), copyTag.getAttribute('target'))
    copyTag = copyTags.iterateNext();
  }
};